import time
import jwt
from django.conf import settings

class JWTTool:
    
    def __init__(self):
        self.key="china_file"
    #参数 userid
    def create_token(self,userid,expire_seconds=60*60*24*7):
        exp = int(time.time()) + expire_seconds
        payload = {
            "userid":userid,
            "exp":exp
        }
        return jwt.encode(key=self.key, payload=payload, algorithm="HS256")

    def decode(self,token):
        return jwt.decode(token, self.key, algorithms=["HS256"])

    def encode(self,payload):
        return jwt.encode(payload, self.key, algorithm="HS256")


#拿到类的实例


my_jwt=JWTTool()
